<%@ page contentType="text/html;charset=UTF-8" language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/include/jstl.jsp" %>
<script language="javascript"> 
function check_bak(){
    var isCheck =getById("notall_0").checked;
    if(isCheck) {
        //时间
        var mydatea = getById("mydatea").value;
        var mydateb = getById("mydateb").value;
        mydatea = mydatea.replace("-" ,"").replace("-" ,"");
        mydateb = mydateb.replace("-" ,"").replace("-" ,"");
        if(mydatea > mydateb){
            alertMsg.info("开始时间不能小于结束时间！");
            getById("mydateb").focus();
            return false;
        }
    }
    //金额
    var amt1 = getById("LIMIT_MIN_AMT").value;
    var amt2 = getById("LIMIT_MAX_AMT").value;                
    if(amt1!="" && amt2!="") {
        if(parseFloat(amt1) > parseFloat(amt2)){
            alertMsg.info("单笔最小金额不能大于单笔最大金额！");
            getById("LIMIT_MAX_AMT").focus();
            return false;
        }
    }
    //每日交易次数 * 单笔最大限额 <= 每日交易限额
    var cou3 = getById("LIMIT_DAY_TIMES").value;
    var amt3 = getById("LIMIT_DAY_AMT").value;
    if(cou3!="" && amt3!="") {
        if(parseFloat(amt2)*parseFloat(cou3) > parseFloat(amt3)){
            alertMsg.info("每日交易次数*单笔最大限额不能大于每日交易限额！"); 
            getById("LIMIT_DAY_AMT").focus();
            return false;
        }
    }
    //每月交易次数 * 单笔最大限额 <= 每月交易限额
    var cou4 = getById("LIMIT_MONTH_TIMES").value;
    var amt4 = getById("LIMIT_MONTH_AMT").value;
    if(cou4!="" && amt4!="") {
        if(parseFloat(amt2)*parseFloat(cou4) > parseFloat(amt4)){
            alertMsg.info("每月交易次数*单笔最大限额不能大于每月交易限额！"); 
            getById("LIMIT_MONTH_AMT").focus();
            return false;
        }
    }
    if(cou3!="" && cou4!="") {
        if(parseFloat(cou4) < parseFloat(cou3)){
            alertMsg.info("每月交易次数不能小于每日交易次数！"); 
            getById("LIMIT_MONTH_TIMES").focus();
            return false;
        }
    }
    if(amt3!="") {
        if(parseFloat(amt3) < parseFloat(amt2)){
            alertMsg.info("每日交易金额不能小于单笔最大金额！"); 
            getById("LIMIT_DAY_AMT").focus();
            return false;
        }
    }
    if(amt4!="") {
        if(parseFloat(amt4) < parseFloat(amt2)){
            alertMsg.info("每月交易金额不能小于单笔最大金额！"); 
            getById("LIMIT_MONTH_AMT").focus();
            return false;
        }
    }
    if(amt3!="" && amt4!="") {
        if(parseFloat(amt4) < parseFloat(amt3)){
            alertMsg.info("每月交易金额不能小于每日交易金额！"); 
            getById("LIMIT_MONTH_AMT").focus();
            return false;
        }
    }
    return true;         
}

function check(){
    var isCheck = getById("notall_0").checked;
    var sMsg    = "结束时间不能小于开始时间！";
    if(isCheck){
        //时间
        var sDate1 = getById("mydatea").value;
        var sDate2 = getById("mydateb").value;
            sDate1 = sDate1.replace("-" ,"").replace("-" ,"");
            sDate2 = sDate2.replace("-" ,"").replace("-" ,"");
        if(sDate1 > sDate2){
            alertMsg.info(sMsg);
            getById("mydateb").focus();
            return false;
        }
    }
    
    var fLimitMinAmt     = idTextToNumber("LIMIT_MIN_AMT"    ),//单笔最小金额
        fLimitMaxAmt     = idTextToNumber("LIMIT_MAX_AMT"    ),//单笔最大金额
        fLimitDayTimes   = idTextToNumber("LIMIT_DAY_TIMES"  ),//限制日交易次数
        fLimitDayAmt     = idTextToNumber("LIMIT_DAY_AMT"    ),//限制日交易金额
        fLimitMonthTimes = idTextToNumber("LIMIT_MONTH_TIMES"),//限制月交易次数
        fLimitMonthAmt   = idTextToNumber("LIMIT_MONTH_AMT"  ),//限制月交易金额
        fLimitYearTimes  = idTextToNumber("LIMIT_YEAR_TIMES" ),//限制年交易次数
        fLimitYearAmt    = idTextToNumber("LIMIT_YEAR_AMT"   );//限制年交易金额
    
    sMsg = "单笔最小金额不能大于单笔最大金额！";
    if(fLimitMinAmt > fLimitMaxAmt){
        alertMsg.info(sMsg);
        getById("LIMIT_MAX_AMT").focus();
        return false;
    }
    
    sMsg = "每日交易限额不能大于每日交易次数*单笔最大限额！";
    if(fLimitDayTimes!="" && fLimitDayAmt!="") {
        if(fLimitDayAmt > fLimitMaxAmt*fLimitDayTimes){
            alertMsg.info(sMsg); 
            getById("LIMIT_DAY_AMT").focus();
            return false;
        }
    }
    
    sMsg = "每月交易限额不能大于每月交易次数*单笔最大限额！";
    if(fLimitMonthTimes!="" && fLimitMonthAmt!="") {
        if(fLimitMonthAmt > fLimitMaxAmt*fLimitMonthTimes){
            alertMsg.info(sMsg);
            getById("LIMIT_MONTH_AMT").focus();
            return false;
        }
    }
    
    sMsg = "每月交易次数不能小于每日交易次数！";
    if(fLimitDayTimes!="" && fLimitMonthTimes!=""){
        if(fLimitMonthTimes < fLimitDayTimes){
            alertMsg.info(sMsg);
            getById("LIMIT_MONTH_TIMES").focus();
            return false;
        }
    }
    
    sMsg = "每日交易金额不能小于单笔最大金额！";
    if(fLimitDayAmt!="") {
        if(fLimitDayAmt < parseFloat(slimitmaxamt)){
            alertMsg.info(sMsg);
            getById("LIMIT_DAY_AMT").focus();
            return false;
        }
    }
    
    sMsg = "每月交易金额不能小于单笔最大金额！";
    if(fLimitMonthAmt!="") {
        if(fLimitMonthAmt < fLimitMaxAmt){
            alertMsg.info(sMsg);
            getById("LIMIT_MONTH_AMT").focus();
            return false;
        }
    }
    
    sMsg = "每月交易金额不能小于每日交易金额！";
    if(fLimitDayAmt!="" && fLimitMonthAmt!="") {
        if(fLimitMonthAmt < fLimitDayAmt){
            alertMsg.info(sMsg);
            getById("LIMIT_MONTH_AMT").focus();
            return false;
        }
    }
    
    sMsg = "每年交易金额不能小于单笔最大金额";
    if(fLimitYearAmt!=""){
        if(fLimitYearAmt<fLimitMaxAmt){
            alertMsg.info(sMsg);
            getById("LIMIT_YEAR_AMT").focus();
            return false;
        }
    }
    
    sMsg = "每年交易金额不能小于每月交易金额";
    if(fLimitYearAmt!="" && fLimitMonthAmt){
        if(fLimitYearAmt<fLimitMonthAmt){
            alertMsg.info(sMsg);
            getById("LIMIT_YEAR_AMT").focus();
            return false;
        }
    }
    
    sMsg = "每年交易限额不能大于每年交易次数*单笔最大限额！";
    if(fLimitYearAmt!="" && fLimitYearTimes){
        if(fLimitYearAmt > fLimitYearTimes*fLimitMaxAmt){
            alertMsg.info(sMsg);
            getById("LIMIT_YEAR_AMT").focus();
            return false;
        }
    }
    
    return true;        
}

function getById(id){
    return document.getElementById(id);
}

function idTextToNumber(id){
    var sText = getById(id).value;
    if(sText == ""){
        return sText;
    }else{
        return parseFloat(sText);
    }
}

function checkNums(obj){
    obj.value = obj.value.replace(/[^\d.]/g,"");
    obj.value = obj.value.replace(/^\./g,"");
    obj.value = obj.value.replace(/\.{2,}/g,".");
    obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
}
        
function chooseDate(){
    getById("mydatea1").style.display = "block";
    getById("mydateb1").style.display = "block";
    getById("indate1" ).style.display = "block";
    getById("mydatea1").className='required textInput';
    getById("mydateb1").className='required textInput';
}

function chooseDate1(){            
    getById("mydatea1").style.display = "none";
    getById("mydateb1").style.display = "none";
    getById("indate1" ).style.display = "none";        
    getById("mydatea1").className = "";
    getById("mydateb1").className = "";
}

function chooseType(obj){
    if(obj == '3'){
        getById('aaa').disabled = false;
        getById('aaa').className='required textInput';//增加class 必输
    }else if(obj == '1'){
        getById('aaa').value     = '';
        getById('aaa').disabled  = true;
        getById('aaa').className = 'number';
    }
}
</script>
<h2 class="contentTitle" style="background-color:#E8F1FD;">添加商户限额</h2>
<div class="pageContent" style="background-color:#E8F1FD;">
  
    <form  method="post" action="540864.tran" onsubmit="navTab.reloadFlag('540800.tran');return validateCallback(this, navTabAjaxDone)" class="pageForm required-validate">
        <input  type="hidden" name="LIMIT_RISK_FLAG"  value="0" />
        <div  class="pageFormContent" layoutH="87"  > 
            <!--商户状态类型是否显示，1:显示 0;不显示 -->
            <c:if test="${ETF.IS_SHOW_LIMIT_COMP_TYPE != '0'}">
                <table border="0" width="900px">
                    <tr height="30px">
                        <td width="17%">商户状态类型：</td>
                        <td>
                            <table>
                                <tr>
                                    <td><input id="all" type="radio"  name= "LIMIT_TYPE"  value="1" onclick="chooseType(this.value);" checked />所有商户</td>
                                    <td colspan="3"><input id="notall" type="radio" name="LIMIT_TYPE"  value="3" onclick="chooseType(this.value);"/>指定商户号</td>
                                    <td><input id="aaa" type="text" name="LIMIT_COMP_CODE" size="14" maxlength="14" onkeyup="checkNums(this)" disabled /></td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </c:if>

            <!--商户及用户业务类型及支付方式是否显示，1:显示 0;不显示 -->
            <table  border="0" width="900px">
                <tr height="30px">
                    <td width="17%">请选择支付方式：</td>
                    <td>
                        <select id="PARENT_CODE" name="PARENT_CODE">
                            <option value="00" selected="selected">00-全部 </option>
                            <option value="01">01-网银</option>                 
                      <!--      <option value="02">02-终端</option>   -->
                            <option value="03">03-消费卡</option>                 
                            <option value="04">04-虚拟账户</option>                 
                            <option value="05">05-快捷支付</option>
                        </select>
                    </td>
                </tr>
            </table>
            <c:if test="${ETF.IS_SHOW_LIMIT_BUS_CODE == '0'}">
                <input id="opeTypeId"        type="hidden"/>
                <input id="LIMIT_BUS_CLIENT" type="hidden"/>
            </c:if>
            <table  border="0" width="900px">
                <tr height="30px">
                    <td width="150px">限额生效时间范围 ：</td>
                    <td>
                        <table>
                            <tr>                             
                                <td><input id="all_0"    type="radio" name = "LIMIT_START_TYPE" onclick="chooseDate1();" value="0" checked /> 永久</td>
                                <td><input id="notall_0" type="radio" name ="LIMIT_START_TYPE"  onclick="chooseDate();"  value="1"  />按生效时间</td>
                                <td>
                                    <input id="mydatea1" name="LIMIT_START_DATE" style="display: none" type="text"  class="date" yearstart="-80" yearend="5" readonly="true" format="yyyy-MM-dd" size="10" />
                                    <span  id="indate1" class="info" style="display: none">~~</span> 
                                    <input id="mydateb1" name="LIMIT_END_DATE" style="display: none" type="text"  class="date" yearstart="-80" yearend="5" readonly="true" format="yyyy-MM-dd" size="10" />
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr height="35px">
                    <td>单笔最小金额：</td>
                    <td>
                        <input type="text" id="LIMIT_MIN_AMT" name="LIMIT_MIN_AMT" value="0" size="30"  max="99999999999.99"  min="0" maxLength="14"  class="required number"/>
                    </td>
                    <td>单笔最大金额：</td>
                    <td>
                        <input type="text" id="LIMIT_MAX_AMT" name="LIMIT_MAX_AMT" value="0" size="30"  max="99999999999.99"  min="0" maxLength="14"  class="required number"/>        
                    </td>
                </tr>
                <tr height="35px">
                    <td>日累计交易次数上限：</td>
                    <td>
                        <input type="text" id="LIMIT_DAY_TIMES"  name="LIMIT_DAY_TIMES"  value="${ETF.LIMIT_DAY_TIMES}"  size="30" maxLength="10" min="1" class="digits" />    
                    </td>
                    <td>日累计交易限额上限：</td>
                    <td>
                        <input type="text" id="LIMIT_DAY_AMT"  name="LIMIT_DAY_AMT"  
                            value="<c:if test="${ETF.LIMIT_DAY_AMT!=null}"><fmt:formatNumber type='currency' value='${ETF.LIMIT_DAY_AMT/100}' pattern='0.00'/></c:if>" 
                            size="30" max="99999999999.99"  min="0" maxLength="14"  class="number" /> 
                    </td>
                </tr>
                <tr height="35px">
                    <td>每月交易次数：</td>
                    <td>
                        <input type="text" id="LIMIT_MONTH_TIMES" name="LIMIT_MONTH_TIMES" value="${ETF.LIMIT_MONTH_TIMES}" size="30" min="1" maxLength="10"  class="digits"/>    
                    </td>
                    <td>每月交易限额：</td>
                    <td>
                        <input type="text" id="LIMIT_MONTH_AMT"  name="LIMIT_MONTH_AMT" 
                            value="<c:if test="${ETF.LIMIT_MONTH_AMT!=null}"><fmt:formatNumber type='currency' value='${ETF.LIMIT_MONTH_AMT/100}' pattern='0.00'/></c:if>" 
                            size="30" maxLength="14"  max="99999999999.99"  min="0" class="number" />
                    </td>
                </tr>
                <tr height="35px">
                    <td>每年交易次数：</td>
                    <td>
                        <input type="text" id="LIMIT_YEAR_TIMES" name="LIMIT_YEAR_TIMES" value="${ETF.LIMIT_YEAR_TIMES}" size="30" min="1" maxLength="10"  class="digits"/>
                    </td>
                    <td>每年交易限额：</td>
                    <td>
                        <input type="text" id="LIMIT_YEAR_AMT"  name="LIMIT_YEAR_AMT" 
                            value="<c:if test="${ETF.LIMIT_YEAR_AMT!=null}"><fmt:formatNumber type='currency' value='${ETF.LIMIT_YEAR_AMT/100}' pattern='0.00'/></c:if>" 
                            size="30" maxLength="14"  max="99999999999.99"  min="0" class="number" />
                    </td>
                </tr>
                <tr height="30px">
                    <td>启用标志：</td>
                    <td colspan="3">
                        <input type="radio" name="IS_USE" value="1" checked>启用</input>
                        <input type="radio" name="IS_USE" value="0" >未启用</input>
                    </td>
                </tr>
                <tr height="30px">
                    <td>备注：</td>
                    <td colspan="3">
                        <textarea name="LIMIT_ADDINFO" cols="60" rows="5"  maxlength="100" >${ETF.LIMIT_ADDINFO}</textarea>
                    </td>
                </tr>
            </table>
        </div>
        <div class="formBar">
            <ul>     
                <li><div class="buttonActive"><div class="buttonContent"><button type="submit" onclick="return check();">保存</button></div></div></li>
                <li><div class="button"><div class="buttonContent"><button type="reset">重置</button></div></div></li>
                <li><div class="buttonActive"><div class="buttonContent"><button type="button" class="close" >返回</button></div></div></li>
            </ul>
        </div>
    </form>
</div>